package com.company.Utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 使用正则提取内容
 */
public class regUtils {
    public static String[] getData(String text){
        //首先判断是否是注释 如果值注释将//去掉翻译后边的内容
        //如果是内容将 key 和 value 进行提取并翻译
       // <string name="long_title">这是一个快捷方式</string>
        String reg1 = "\\s*<string.*>(.*)</string>\\s*";
        Pattern pattern = Pattern.compile(reg1);
        Matcher matcher = pattern.matcher(text);
        int count = 0;
        if(matcher.find()){
            //System.out.print("是内容"+matcher.group(1));
            return new String[]{text,matcher.group(1)};
        }else {
            //System.out.print("是注释");
            return new String[]{text,text(text)};
        }
    }

    public static String text(String text){
        String reg1 = "\\s*<!--(.*)-->\\s*";
        Pattern pattern = Pattern.compile(reg1);
        Matcher matcher = pattern.matcher(text);
        int count = 0;
        if(matcher.find()){
            //System.out.print("注解内容"+matcher.group(1));
            return matcher.group(1);
        }else {
            return null;
        }
    }
}
